package com.itheima.springbootwebtlias.service.Impl;

import com.itheima.springbootwebtlias.mapper.EmpMapper;
import com.itheima.springbootwebtlias.mapper.StudentMapper;
import com.itheima.springbootwebtlias.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ReportServiceImpl  implements ReportService {

    @Autowired
    EmpMapper  empMapper;

    @Autowired
    StudentMapper studentMapper;





    // 统计每个职位的个数
    @Override
    public Map jobCount() {
        //1.调用业务层Service的功能方法，查询职位个数
        List<Map> jobList = empMapper.jobCount();

        //2.处理查询结果
        Map map = new HashMap();
        map.put("jobList",jobList.stream().map(item->item.get("name")).collect(Collectors.toList()));
        map.put("dataList",jobList.stream().map(item->item.get("value")).collect(Collectors.toList()));

        //3.返回结果
        return map;
    }

    //  统计员工性别的个数
    @Override
    public List<Map> genderCount() {
       //1.调用业务层Service的功能方法，查询性别个数
        return empMapper.genderCount();
    }

    //统计每个班级人数
    @Override
    public Map studentCount() {
        List<Map> clazzList = studentMapper.studentCount();

        //2.处理查询结果
     Map map = new HashMap();
     map.put("clazzList",clazzList.stream().map(item->item.get("name")).collect(Collectors.toList()));
     map.put("dataList",clazzList.stream().map(item->item.get("value")).collect(Collectors.toList()));

     return  map;
    }

    //学历统计
    @Override
    public List<Map> degreeCount() {
       return studentMapper.degreeCount();
    }


}
